package com.lu.library.base

import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.FrameLayout
import androidx.databinding.DataBindingUtil
import androidx.databinding.ViewDataBinding
import androidx.fragment.app.Fragment

abstract class BaseFragment<VB: ViewDataBinding>:Fragment() {

    protected lateinit var binding: VB
    /**
     * 初始化数据
     */
    abstract fun initData()
    protected open fun initViews(){}

    /**
     * 布局资源文件
     * @return 布局资源文件
     */
    abstract fun layoutResId(): Int
    override fun onCreateView(
        inflater: LayoutInflater,
        container: ViewGroup?,
        savedInstanceState: Bundle?
    ): View? {
//        if (container ==null){
//            val parent = FrameLayout(requireContext())
//            parent.layoutParams = ViewGroup.LayoutParams(
//                ViewGroup.LayoutParams.MATCH_PARENT,
//                ViewGroup.LayoutParams.MATCH_PARENT
//            )
//            binding = DataBindingUtil.inflate(inflater, layoutResId(), parent, false)
//        }else {
            binding = DataBindingUtil.inflate(inflater, layoutResId(), container, false)
//        }


        return binding.root
    }
    override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
        super.onViewCreated(view, savedInstanceState)

        initViews();
        initData();
        initListener();
    }
    protected open fun initListener(){

    }
}